package com.hn.shopadmin.dto;

import com.google.common.base.Converter;
import com.hn.kiss.modules.sys.shopdb.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import org.springframework.format.annotation.DateTimeFormat;

@ApiModel(description = "登录返回信息实体")
@Accessors(chain = true)
@Data
public class UserLoginDTO {
    @ApiModelProperty("token")
    private String token;

    @ApiModelProperty("id")
    private String id;

    @ApiModelProperty("昵称")
    private String nickname;

    @ApiModelProperty("姓名")
    private String name;

    @ApiModelProperty("性别")
    private String sex;

    @ApiModelProperty("出生日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private String dateofbirth;

    @ApiModelProperty("邮箱")
    private String emall;

    @ApiModelProperty("手机号")
    private String phone;

    @ApiModelProperty("角色")
    private String role;

    public User convertToUser(){
        UserLoginDTOConvert loginDTOConvert = new UserLoginDTOConvert();
        return loginDTOConvert.convert(this);
    }
    public UserLoginDTO convertFor(User user){
        UserLoginDTOConvert loginDTOConvert = new UserLoginDTOConvert();
        return loginDTOConvert.reverse().convert(user);
    }

    public class UserLoginDTOConvert extends Converter<UserLoginDTO, User>{

        @Override
        public User doForward(UserLoginDTO loginDTO) {
            User user = new User();
            BeanUtils.copyProperties(loginDTO, user);
            return user;
        }

        @Override
        public UserLoginDTO doBackward(User user) {

            UserLoginDTO userLoginDTO = new UserLoginDTO();
            BeanUtils.copyProperties(user, UserLoginDTO.this);
            return userLoginDTO;
        }
    }

}
